<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			input{
				width: 150px;
			}
			#body{
				width: 100%;
			}
			
			
		</style>
	</head>
	<body>
		<div id="body" >
			用户名:<input name="username" type="text" /><br />
			密码:<input name="password" type="password" />
			<button type="button" onclick="login()">登录</button>
			
			
			
			<div style="margin-top: 50px;width: 100%;">
				token:<input name="token" type="text" style="width: 500px;"/><br />
				<button onclick="hello('http://localhost:8070/security-jwt/hello')">hello</button>
				<button onclick="hello('http://localhost:8070/security-jwt/admin')">admin</button>
				<button onclick="hello('http://localhost:8070/security-jwt/user')">user</button>
			</div>
		</div>
		
		
		
		
		<script type="text/javascript" src="js/jquery-3.0.0.min.js"></script>
		<script type="text/javascript">
		
		
		function login(){
			var username = $("#body [name=username]").val();
			var password = $("#body [name=password]").val();
			var parmDate = {
				"username" : username,
				"password" : password
			}
			$.ajax({
				url:'http://localhost:8070/security-jwt/login',
				data:parmDate,
				dataType:'text',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					alert("登录成功");
					$("#body [name=token]").val(data);
				},
				error:function(xhr,type,errorThrown){
					alert("error");
				}
			});
		}
		
		function hello(url){
			var token = $("#body [name=token]").val();
			console.log(token)
			$.ajax({
				url:url,
				beforeSend: function(request) {
					request.setRequestHeader("Authorization", token);
				}, 
				dataType:'text',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					alert(data);
				},
				error:function(xhr,type,errorThrown){
					alert("error");
				}
			});
		}
		
		
		</script>
	</body>
</html>
